package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.utils.DateUtils;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Resource
    private MemberDao memberDao;
    @Resource
    private OrderDao orderDao;
    @Override
    public Map<String, Object> getBusinessReport() throws Exception {
        Map<String, Object> result = new HashMap<>();
        //获得当前日期
        String today = DateUtils.parseDate2String(new Date());
        result.put("reportDate",today);

        //今日新增会员数
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        result.put("todayNewMember",todayNewMember);

        //总会员数量
        Integer totalMember = memberDao.findMemberTotalCount();
        result.put("totalMember",totalMember);

        //本周新增会员数
        //获得本周一的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeekMonday);
        result.put("thisWeekNewMember",thisWeekNewMember);

        //本月新增会员数
        //获得本月第一天的日期
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);
        result.put("thisMonthNewMember",thisMonthNewMember);

        //今日预约数
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        result.put("todayOrderNumber",todayOrderNumber);

        //今日到诊人数
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        result.put("todayVisitsNumber",todayVisitsNumber);

        //本周预约数
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(thisWeekMonday);
        result.put("thisWeekOrderNumber",thisWeekOrderNumber);

        //本周到诊人数
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(thisWeekMonday);
        result.put("thisWeekVisitsNumber",thisWeekVisitsNumber);

        //本月预约数
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);
        result.put("thisMonthOrderNumber",thisMonthOrderNumber);

        //本月到诊人数
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);
        result.put("thisMonthVisitsNumber",thisMonthVisitsNumber);

        //热门套餐（取前4）
        List<Map> hotSetmeal = orderDao.findHotSetmeal();
        result.put("hotSetmeal",hotSetmeal);

        return result;
    }
}
